package yunjiao.designpatterns.observer;

/**
 * 邮件订阅者
 *
 * @author yangyunjiao
 */
public class EmailSubscriber implements Observer {
    private final String name;
    private final String email;

    public EmailSubscriber(String name, String email) {
        this.name = name;
        this.email = email;
    }

    @Override
    public void update(Subject subject) {
        NewsPublisher publisher = (NewsPublisher) subject;
        System.out.println("发送邮件到 " + email + ": 亲爱的 " + name +
                ", 有新新闻 - " + publisher.getLatestNews());
    }

    @Override
    public String getName() {
        return name + "(邮件订阅者)";
    }
}
